package org.nidy.programexercise.MethodCitation;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ConstructorCitation {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        Collections.addAll(list,"张山丰,65","张翠山,43,","赵敏,18","张无忌,19","韦一笑,22","韦小宝,25");
        /**
         * 1.使用lambda表达式
         * 2.使用方法引用
         * 3.使用构造器引用
         */
        System.out.println("======================使用匿名内部类方式==================");
        List<Student> studentCollect = list.stream().map(new Function<String, Student>() {
            @Override
            public Student apply(String s) {
                String[] split = s.split(",");
                String name = split[0];
                int age = Integer.parseInt(split[1]);
                return new Student(name, age);
            }
        }).collect(Collectors.toList());
        studentCollect.forEach(System.out::println);
        System.out.println("======================使用构造方法引用方式==================");
        List<Student> collect = list.stream().map(Student::new).collect(Collectors.toList());
        collect.forEach(System.out::println);

    }
}
